import os

basedir = os.path.abspath(os.path.dirname(__file__))

class Config:
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
    FLASKY_ADMIN = os.environ.get('FLASKY_ADMIN')
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_ECHO = False
    LOG_LEVEL = os.environ.get('LOG_LEVEL') or 'INFO'
    LOG_FILENAME = os.environ.get('LOG_FILENAME') or 'flaskapp.log'
    
    @staticmethod
    def init_app(app):
        pass

# 本地开发环境 
class DevelopmentConfig(Config):
    # 调试模式
    DEBUG = True
    
    # 数据库配置
    SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URI') or \
                              'mysql+mysqlconnector://demo:123456@192.168.102.128:3306/authbase?charset=utf8&auth_plugin=mysql_native_password'
    # 连接池配置
    SQLALCHEMY_POOL_SIZE = os.environ.get('SQLALCHEMY_POOL_SIZE') or 10
    SQLALCHEMY_POOL_TIMEOUT = os.environ.get('SQLALCHEMY_POOL_SIZE') or 60
    SQLALCHEMY_POOL_RECYCLE = os.environ.get('SQLALCHEMY_POOL_RECYCLE') or 1800
    
    # redis配置
    REDIS_URL = os.environ.get('REDIS_URL') or \
                'redis://:123456@localhost:6379/0'
    REDIS_MAX_CONNECTIONS = os.environ.get('REDIS_MAX_CONNECTIONS') or 10
    REDIS_TIMEOUT = os.environ.get('REDIS_TIMEOUT') or 10
    REDIS_CONNECTION_TIMEOUT = os.environ.get('REDIS_CONNECTION_TIMEOUT') or 5

# 生产及测试环境
class ProductionConfig(Config):
    # 数据库配置
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI')
    # 连接池配置
    SQLALCHEMY_POOL_SIZE = os.environ.get('SQLALCHEMY_POOL_SIZE') or 20
    SQLALCHEMY_POOL_TIMEOUT = os.environ.get('SQLALCHEMY_POOL_SIZE') or 60
    SQLALCHEMY_POOL_RECYCLE = os.environ.get('SQLALCHEMY_POOL_RECYCLE') or 600

    # redis配置
    REDIS_URL = os.environ.get('REDIS_URL')
    REDIS_MAX_CONNECTIONS = os.environ.get('REDIS_MAX_CONNECTIONS') or 50
    REDIS_TIMEOUT = os.environ.get('REDIS_TIMEOUT') or 10
    REDIS_CONNECTION_TIMEOUT = os.environ.get('REDIS_CONNECTION_TIMEOUT') or 5

config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}
